# -*- coding: utf-8 -*-
# $Id: aboutdialog.py 17 2009-02-15 00:12:19Z gkuznets $

# Copyright 2008, 2009 Grigoriy Kuznetsov (gkuznets@yandex.ru)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4 import QtCore, QtGui, QtSvg
from PyQt4.QtCore import QString, QObject
from PyQt4.QtGui import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QTabWidget, QPushButton, QTextEdit, QWidget

class AboutDialog(QDialog):
  """Диалог 'О программе'"""
  
  def __init__(self):
    QDialog.__init__(self)
    self.create_layout()
    self.setWindowTitle(u"О программе")
  
  def create_layout(self):
    layout = QVBoxLayout()
    tabs = QTabWidget()
    
    info_tab = QWidget()
    ilayout = QVBoxLayout()
    logo = QtSvg.QSvgWidget(u":/img/logo.svg")
    logo.setFixedSize(500, 500)
    ilayout.addWidget(logo)
    info_tab.setLayout(ilayout)
    text = QLabel(u"<b><font color='green' size='+2'>mpcheckup</font></b><br/>"+
                  u"© Гриша Кузнецов, 2008, 2009 <a href='mailto:gkuznets@gmail.com'>gkuznets@yandex.ru</a><br/>"+
                  u"<a href='http://code.google.com/p/mpcheckup/'>http://code.google.com/p/mpcheckup/</a>")
    ilayout.addWidget(text)
    tabs.addTab(info_tab, u"Аьоке!")
    
    help_tab = QWidget()
    hlayout = QVBoxLayout()
    help = QLabel(QString(u"""Доступны следующие команды:
        №№# \t\t послать пачку №№ на проверку задачи #
        №№<пробел> \t забрать пачку с проверки
        а \t\t добавить пачку работ
        f№№ \t\t пометить/снять помету с пачки №№
        u \t\t отменить последнее действие
        second \t\t начать вторую проверку
        <esc> \t\t удаляет текущие символы команды
        h \t\t помощь(выводит это сообщение)
        """))

    hlayout.addWidget(help)
    hlayout.addStretch(1)
    help_tab.setLayout(hlayout)
    tabs.addTab(help_tab, u"Команды")
    
    lic = QtCore.QFile("license.txt")
    if lic.exists():
      license = QTextEdit()
      lic.open(QtCore.QFile.ReadOnly)
      s = QtCore.QTextStream(lic)
      license.insertPlainText(s.readAll())
      license.setReadOnly(True)
      tabs.addTab(license, u"Лицензия")
    
    blayout = QHBoxLayout()
    blayout.addStretch(1)
    ok_btn = QPushButton("OK")
    self.connect(ok_btn, QtCore.SIGNAL("clicked()"), self.accept)
    blayout.addWidget(ok_btn)
    
    layout.addWidget(tabs)
    layout.addStretch(1)
    layout.addLayout(blayout)
    self.setLayout(layout)
